package com.baosaas.api.baseInfo.util;

import java.util.Calendar;
import java.util.UUID;

/**
 * 组织请求头数据
 */
public class RequestUtils {

    public static Head getHeader(String suburl) {
        Head head = new Head(suburl);
        return head;
    }

    private static String getNowDate() {
        Calendar now = Calendar.getInstance();
        int y = now.get(Calendar.YEAR);
        int m = now.get(Calendar.MONTH) + 1;
        m = m < 10 ? ('0' + m) : m;
        int d = now.get(Calendar.DAY_OF_MONTH);
        d = d < 10 ? ('0' + d) : d;
        int h = now.get(Calendar.HOUR_OF_DAY);
        h = h < 10 ? ('0' + h) : h;
        int minute = now.get(Calendar.MINUTE);
        int second = now.get(Calendar.SECOND);
        minute = minute < 10 ? ('0' + minute) : minute;
        second = second < 10 ? ('0' + second) : second;
        return y + "" + m + "" + d + "" + h + "" + minute + "" + second;
    }

    public static class Head {
        private String sysId;//系统接入码
        private String primaryCode;//系统授权code "STM75JHKSHKJDHKJS" 测试 "STM75JKSHDKJH76G8LP" 正式
        private String version;//接口版本号
        private String requestSn;//请求秘钥
        private String functionId;//请求接口名
        private String sendTime;//请求时间

        public Head(String suburl) {
            this.sysId = "STM75";
            this.sendTime = getNowDate();
            this.functionId = suburl;
            this.version = "2.0";
            this.primaryCode = "STM75JHKSHKJDHKJS";
            this.requestSn = UUID.randomUUID().toString();
        }

        public String getSysId() {
            return sysId;
        }

        public void setSysId(String sysId) {
            this.sysId = sysId;
        }

        public String getPrimaryCode() {
            return primaryCode;
        }

        public void setPrimaryCode(String primaryCode) {
            this.primaryCode = primaryCode;
        }

        public String getVersion() {
            return version;
        }

        public void setVersion(String version) {
            this.version = version;
        }

        public String getRequestSn() {
            return requestSn;
        }

        public void setRequestSn(String requestSn) {
            this.requestSn = requestSn;
        }

        public String getFunctionId() {
            return functionId;
        }

        public void setFunctionId(String functionId) {
            this.functionId = functionId;
        }

        public String getSendTime() {
            return sendTime;
        }

        public void setSendTime(String sendTime) {
            this.sendTime = sendTime;
        }
    }
}
